{% extends "PopshouseAdminBundle::layout.html.twig" %}

{% block title %}
Categorie "{{ domain }}" bewerken
{% endblock %}
{% block js %}

	var last = parseInt($('.last').attr('index'));
	if(isNaN(last))
	   last = 0;
	$('textarea').elastic();
	//$('textarea').livequery(function(){$('textarea').elastic();});
	$('.add').click(function(){
	    last++;
	   var template='<li index="' + last + '">'
	       +'<a class="showhide action" index="' + last + '"><span>+</span></a><a class="remove action" index="' + last + '"><span>X</span></a><input type="text" name="strings['+last+'][key]" width="400" />'
	        +'<ul style="display:none;">'
	        {% for lang in translation.langs %}
	        +'<li style="vertical-align:top;">'
	           +'{{lang}} &raquo; <textarea name="strings['+last+'][{{ lang }}]" style="border:3px solid #202020;background-color:#1f1f1f;color:#ccc;max-height:800px;font-size:12px;width:800px;"></textarea>'
	        +'</li>'
	        {% endfor %}
	        +'</ul>'
	    +'</li>';
	   
	    $('.strings').append(template);
	    {% for lang in translation.langs %}
           $('textarea[name="strings['+last+'][{{ lang }}]"]').elastic();
        {% endfor %}
	});
	
	$('.showhide').live('click',function(){
	   var id = parseInt($(this).attr('index'));
	   $ul = $('li[index="' + id + '"] ul');
	   $ul.toggle();
	   if($ul.is(':hidden'))
	       $(this).children().first().text('+');
	   else
	       $(this).children().first().text('-');
	});
	$('.remove').live('click',function(){
	   var id = parseInt($(this).attr('index'));

	   var answer = confirm('Verwijder zin' + $('input[name="strings['+ id +'][key]"]').val() +'?');
	    if (answer){
	        $('li[index="' + id + '"]').remove();
	    }
	});
{% endblock %}

{% block content %}
<h2>Categorie: {{ domain }} bewerken</h2>
<form action="{{ path('trans_save', {'domain' : domain}) }}" method="post">
<ul class="strings">
{% for key in translation.keys %}
	<li {% if loop.last %}class="last"{% endif %} index="{{loop.index}}"><a class="showhide action" index="{{loop.index}}"><span>+</span></a><a class="remove action" index="{{loop.index}}"><span>X</span></a>
	   <input type="text" name="strings[{{loop.index}}][key]" value="{{ key }}" width="400" />
	    <ul style="display:none;">
		{% for lang in translation.langs %}
		<li style="vertical-align:top;">
		  {{lang}} &raquo; <textarea name="strings[{{loop.parent.loop.index}}][{{ lang }}]" style="border:3px solid #202020;background-color:#1f1f1f;color:#ccc;max-height:800px;font-size:12px;width:800px;">{{ translation.strings[key][lang]|default(translation.strings[key]['nl']) }}</textarea>
		</li>
		{% endfor %}
		</ul>
	</li>
	{% endfor %}
</ul>
<p><a class="add action"><span>Zin toevoegen</span></a></p>
<input type="submit" name="submit" value="Opslaan" />
</form>
{% endblock %}